package mapreduce.flowcount.task3;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class FlowMapper extends Mapper<LongWritable, Text, Text, FlowBean> {
    /*
      将K1和V1转为K2和V2:
      K1              V1
      0               1363157985059 	13600217502	00-1F-64-E2-E8-B1:CMCC	120.196.100.55	www.baidu.com	综合门户	19	128	1177	16852	200
     ------------------------------
      K2                                   V2
      13600217502                           FlowBean(19	128	1177	16852)
     */
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        //1.拆分数据
        String[] splitLine = value.toString().split("\t");
        //2.得到手机号，上行数据包，下行数据包，上行流量总和，下行流量总和
        String phoneNumber = splitLine[1];
        String upPackCount = splitLine[6];
        String downPackCount = splitLine[7];
        String upFlowCount = splitLine[8];
        String downFlowCount = splitLine[9];

        FlowBean flowBean = new FlowBean(Integer.parseInt(upPackCount), Integer.parseInt(downPackCount), Integer.parseInt(upFlowCount), Integer.parseInt(downFlowCount));

        context.write(new Text(phoneNumber), flowBean);
    }
}
